from transformers import MarianMTModel, MarianTokenizer
src = 'de'  # source language
trg = 'ZH'  # target language
src_text = [
    '>>zh<< Er aber sprach: Das ist die Gottlosigkeit. \
Und er warf sie in das Epha und warf den Klumpen Blei oben aufs Loch.',
]
model_name = f'D:/gitee_codes/transformer-learning/models/Helsinki-NLP/opus-mt-{src}-{trg}'
tokenizer = MarianTokenizer.from_pretrained(model_name)
model = MarianMTModel.from_pretrained(model_name)
translated = model.generate(**tokenizer.prepare_translation_batch(src_text))
print([tokenizer.decode(t, skip_special_tokens=True) for t in translated])